package Features.MainMenu
{
	import com.greensock.TweenLite;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.SFramework.Architechture.SViewNode;
	import org.SFramework.Core.SFramework;
	import org.SuiComponents.SuiSimpleButton;
	
	public class MainMenu extends SViewNode
	{
		private var btnPlayGame:SuiSimpleButton;
		public function MainMenu()
		{			
			super();
		}
		
		override public function onInit(initData:Object):Boolean
		{
			var bgMc:Sprite	=	SFramework.singleton.resourceManager.getImmediateResourceInst( Assets.assetsSwfName, "menuBg" );
			addChild( bgMc );
			
			btnPlayGame							=	new SuiSimpleButton("Play");
			btnPlayGame.title.textAlign			=	"center";
			btnPlayGame.title.textVerticalAlign	=	"center";
			btnPlayGame.title.fontName			=	"WoodLook";
			btnPlayGame.title.embedFont			=	true;
			btnPlayGame.title.textSize			=	15;
			btnPlayGame.title.enabled			=	true;
			btnPlayGame.title.textColor			=	0xffffff;
			btnPlayGame.x						=	73;
			btnPlayGame.y						=	305;
			btnPlayGame.setSize( 176, 30 );
			btnPlayGame.setSWFSource( Assets.assetsSwfName, "btnPostScore" );
			btnPlayGame.addEventListener( MouseEvent.CLICK, handleBtnPlayGame );
			addChild( btnPlayGame );
						
			//=================
			
			var hog:MovieClip		=	bgMc.getChildByName( "Hog" ) as MovieClip;
			var aniPopup:Boolean	=	true;
			hog.gotoAndPlay( "popup" );
			TweenLite.delayedCall( Math.random() * 2.0 + 2.0, changeAnim );
			function changeAnim():void
			{
				hog.gotoAndPlay( "hide" );	
				TweenLite.delayedCall( 0.5, hog.gotoAndPlay, ["popup"] );
				TweenLite.delayedCall( Math.random() * 2.0 + 2.0, changeAnim );
			}
						
			return true;
		}
		
		override public function onShow(initData:Object):void
		{
			
		}
		
		override public function onHide(onHideComplete:Function):void
		{
			onHideComplete.call();
		}
		
		public function handleBtnPlayGame( e:Event ):void
		{
			Application.goRatField();
		}
	}
}